import UIKit

enum DivisionByZeroError: Error {
    case zeroDivisior
}

func divide(_ divided: Int, by divisor: Int) throws -> Double {
    guard divisor != 0 else {
        throw DivisionByZeroError.zeroDivisior
    }

    return Double(divided) / Double(divisor)
}

do {
    let result = try divide(10, by: 2)
    print(result)
} catch  {
    print("error dividing numbers : \(error)")
}



func performCalculation( block: () throws -> Void) rethrows {
    // 执行一些操作...
    try block() // 调用可能抛出错误的闭包
    // 执行其他操作...
}

func divideAndPrint(_ dividend: Int, by divisor: Int) throws {
    let result = try divide(dividend, by: divisor)
    print(result)
}

do {
    try performCalculation {
        try divideAndPrint(10, by: 2)
    }
    try performCalculation {
        try divideAndPrint(10, by: 2) // 调用可能抛出错误的函数
    }
} catch {
    print("Error performing calculation: \(error)")
}
